package domain;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Date;


/**
 * The persistent class for the deelnemer database table.
 * 
 */
@Entity
@Table(name="deelnemer")
@NamedQueries({
    @NamedQuery(name = "Deelnemer.findByReserveringId", query = "SELECT d FROM Deelnemer d WHERE d.id.reserveringId = :reservering_id"),
    @NamedQuery(name = "Deelnemer.findByDeelnemerPK", query = "SELECT d FROM Deelnemer d WHERE d.id.persoonId = :persoon_id AND d.id.reserveringId = :reservering_id")})
public class Deelnemer implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private DeelnemerPK id;

    @Temporal( TemporalType.DATE)
	private Date terugtrekkingsdatum;

	//bi-directional many-to-one association to Reservering
    @ManyToOne
	@JoinColumn(name="reservering_id", nullable=false, insertable=false, updatable=false)
	private Reservering reservering;

	//bi-directional many-to-one association to Persoon
    @ManyToOne
	@JoinColumn(name="persoon_id", nullable=false, insertable=false, updatable=false)
	private Persoon persoon;

    public Deelnemer() {
    }

	public DeelnemerPK getId() {
		return this.id;
	}

	public void setId(DeelnemerPK id) {
		this.id = id;
	}
	
	public Date getTerugtrekkingsdatum() {
		return this.terugtrekkingsdatum;
	}

	public void setTerugtrekkingsdatum(Date terugtrekkingsdatum) {
		this.terugtrekkingsdatum = terugtrekkingsdatum;
	}

	public Reservering getReservering() {
		return this.reservering;
	}

	public void setReservering(Reservering reservering) {
		this.reservering = reservering;
		if(id==null) {
			id = new DeelnemerPK();
		}
		id.setReserveringId(reservering.getReserveringId());
	}
	
	public Persoon getPersoon() {
		return this.persoon;
	}

	public void setPersoon(Persoon persoon) {
		this.persoon = persoon;
		if(id==null) {
			id = new DeelnemerPK();
		}
		id.setPersoonId(persoon.getPersoonId());
	}
	public String toString() {
		return persoon.getVoornaam() + " " + persoon.getAchternaam();
	}
}
